/**
 * @description 广场页 api
 * @author chengpeng
 */

const router = require('koa-router')()
const {
    loginCheck
} = require('../../middlewares/loginCheckes')
const {
    getBlogListStr
} = require('../../utils/blog')
const {
    getSquareBlogList
} = require('../../controller/blog-square')


router.prefix('/api/square')

router.get('/loadMore/:pageIndex', loginCheck, async (ctx, next) => {
    let {
        pageIndex
    } = ctx.params
    pageIndex = parseInt(pageIndex)

    const result = await getSquareBlogList(pageIndex)
    // 渲染为html字符串
    result.data.blogListTpl = getBlogListStr(result.data.blogList)
    ctx.body = result
})

module.exports = router